package com.vulb.logic;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import com.j256.ormlite.dao.RuntimeExceptionDao;
import com.vulb.application.GlobalContext;
import com.vulb.application.keyBean;
import com.vulb.bean.Session;
import com.vulb.db.DbHelper;
import com.vulb.network.http.VulbHttp;
import com.vulb.protocal.http.Response;

public class Login extends BasicLogic {
    public int login(String mAccount, String mPwd) {
        HashMap<String, Object> params = new HashMap<String, Object>();
        keyBean md5 = new keyBean();
        String passwordmd5 = md5.getkeyBeanofStr(mPwd);
        params.put("mailAddress", mAccount);
        params.put("password", passwordmd5);
        params.put("needToken","0");
        
        Response response = VulbHttp.post(VulbHttp.url, params);
        
        if (response.errno == Response.SUCCESS) 
        {
            SessionManager sm = SessionManager.getInstance();
            int uid = Integer.valueOf(response.data.get("userId").toString());
            String sessionid = (String) response.data.get("sessionId");
            Session s = new Session(uid,sessionid,Calendar.getInstance(),mAccount,mPwd);
            sm.login(s);
        }
        return response.errno;
    }
}